﻿package net.wangit.dev.chart;

import net.wangit.context.ActionContext;
import net.wangit.dev.DomainAction;
import net.wangit.dev.ObjectChecker;
import net.wangit.jdbc.DB;
import net.wangit.util.Checker;
import net.wangit.view.chart.ChartCache;

public class DeleteChartAction extends DomainAction {

	private static final String SQL_CHECK = "select l from CHART where cid=?";
	private static final String SQL_DELETE = "delete from CHART where cid=?";

	public DeleteChartAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String chartId = ac.getRequestParameter("chartid");
		if (!Checker.isEmpty(chartId)) {
			net.wangit.MapList list = db.query(
					DeleteChartAction.SQL_CHECK, chartId, 2);
			if (ObjectChecker.invalid(ac, list, "l"))
				return;
			db.execute(DeleteChartAction.SQL_DELETE, chartId, 2);
			ChartCache.clear(domain, chartId);
			ChartReferenceUtil.update(db, domain, chartId, "");
		}
	}
}
